<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    <%@ include file="../../share/layoutIndex.jsp"%> 
  </head>
  
  <body>
<div class="titlePanel">
    <div class="title-search">
        <table>
            <tr>
                <td>
                    <div id="queryCondition" class="btn-group">
                        <a class="btn btn-default dropdown-text" data-toggle="dropdown">选择条件</a>
                        <a class="btn btn-default dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></a>
                        <ul class="dropdown-menu">
                            <li><a data-value="shortName">公司名称</a></li>
                            <li><a data-value="organizeName">中文名称</a></li>
                            <li><a data-value="manager">负责人</a></li>
                        </ul>
                    </div>
                </td>
                <td style="padding-left: 2px;">
                    <input id="txt_Keyword" type="text" class="form-control" placeholder="请输入要查询关键字" style="width: 200px;" />
                </td>
                <td style="padding-left: 5px;">
                    <a id="btn_Search" class="btn btn-primary"><i class="fa fa-search"></i>&nbsp;查询</a>
                </td>
            </tr>
        </table>
    </div>
    <div class="toolbar">
        <div class="btn-group">
            <a id="lr-replace" class="btn btn-default" onclick="reload();"><i class="fa fa-refresh"></i>&nbsp;刷新</a>
            <a id="lr-add" class="btn btn-default" onclick="btn_add()"><i class="fa fa-plus"></i>&nbsp;新增</a>
            <a id="lr-edit" class="btn btn-default" onclick="btn_edit()"><i class="fa fa-pencil-square-o"></i>&nbsp;编辑</a>
            <a id="lr-delete" class="btn btn-default" onclick="btn_delete()"><i class="fa fa-trash-o"></i>&nbsp;删除</a>
        </div>
        
    </div>
</div>
<div class="gridPanel">
    <table id="gridTable"></table>
</div>
<script >
    $(document).ready(function () {
        initialPage();
        GetGrid();
    });
	
    //重设(表格)宽高
    function initialPage() {
        //resize重设(表格、树形)宽高
        $(window).resize(function (e) {
            window.setTimeout(function () {
                $('#gridTable').setGridWidth(($('.gridPanel').width()));
                $("#gridTable").setGridHeight($(window).height() - 108.5);
            }, 200);
            e.stopPropagation();
        });
    }
	
    //加载表格
    function GetGrid() {
        var selectedRowIndex = 0;
        var $gridTable = $('#gridTable');
        $gridTable.jqGrid({
            url: "<%=basePath%>sysOrganize/treeGridJson.do",
            datatype: "json",
            height: $(window).height() - 108.5,
            autowidth: true,
            colModel: [
                { label: '主键', name: 'organizeId', hidden: true },
                { label: "公司名称", name: "organizeName", width: 300, align: "left", sortable: false },
                { label: "简称", name: "shortName", width: 150, align: "left", sortable: false },
				{ label: "联系电话", name: "organizeTelphone", width: 100, align: "left", sortable: false },
				{ label: "电子邮箱", name: "organizeEmail", width: 100, align: "left", sortable: false },
				{ label: "地址", name: "organizeAddress", width: 100, align: "left", sortable: false },
                { label: "负责人", name: "manager", width: 100, align: "left", sortable: false },
				{ label: "排序码", name: "sortCode", index: "sortCode", width: 50, align: "left" },
                {
                    label: "有效", name: "isEnabled", index: "isEnabled", width: 50, align: "center",
                    formatter: function (cellvalue, options, rowObject) {
                        return cellvalue == 1 ? "<i class=\"fa fa-toggle-on\"></i>" : "<i class=\"fa fa-toggle-off\"></i>";
                    }
                },
                { label: "备注", name: "otherMark", width: 200, align: "left", sortable: false }
            ],
            treeGrid: true,
            treeGridModel: "nested",
            ExpandColumn: "shortName",
            rowNum: "all",
            rownumbers: true,
            onSelectRow: function () {
                selectedRowIndex = $("#" + this.id).getGridParam('selrow');
            },
            gridComplete: function () {
                $("#" + this.id).setSelection(selectedRowIndex, false);
            }
        });
		
        //查询条件设置
        $("#queryCondition .dropdown-menu li").click(function () {
            var text = $(this).find('a').html();
            var value = $(this).find('a').attr('data-value');
            $("#queryCondition .dropdown-text").html(text).attr('data-value', value)
        });
		
        //查询事件
        $("#btn_Search").click(function () {
            $gridTable.jqGrid('setGridParam', {
                postData: {
                    condition: $("#queryCondition").find('.dropdown-text').attr('data-value'),
                    keyword: $("#txt_Keyword").val()
                }
            }).trigger('reloadGrid');
        });
		
        //查询回车事件
        $('#txt_Keyword').bind('keypress', function (event) {
            if (event.keyCode == "13") {
                $('#btn_Search').trigger("click");
            }
        });
    }
	
    //新增
    function btn_add() {
        var parentId = $("#gridTable").jqGridRowValue("organizeId");
        dialogOpen({
            id: "Form",
            title: '添加机构',
            url: '<%=basePath%>jsp/manageSystem/sysOrganize/form.do?parentId=' + parentId,
            width: "750px",
            height: "500px",
            callBack: function (iframeId) {
                top.frames[iframeId].AcceptClick();
            }
        });
    };
	
    //编辑
    function btn_edit() {
        var keyValue = $("#gridTable").jqGridRowValue("organizeId");
        if (checkedRow(keyValue)) {
            dialogOpen({
                id: "Form",
                title: '修改机构',
                url: '<%=basePath%>jsp/manageSystem/sysOrganize/form.do?keyValue=' + keyValue,
                width: "750px",
                height: "500px",
                callBack: function (iframeId) {
                    top.frames[iframeId].AcceptClick();
                }
            });
        }
    }
	
    //删除
    function btn_delete() {
        var keyValue = $("#gridTable").jqGridRowValue("organizeId");
        if (keyValue) {
            $.RemoveForm({
                url: "<%=basePath%>sysOrganize/del.do",
                param: { keyValue: keyValue },
                success: function (data) {
                    $("#gridTable").resetSelection();
                    $("#gridTable").trigger("reloadGrid");
                }
            })
        } else {
            dialogMsg('请选择需要删除的数据项！', 0);
        }
    }
</script>
</body>
</html>
